package com.ce.sys.login.model;

import java.util.Date;

public class UserIdEncrypt{
    public static void main(String[] args){
    	System.out.println(UserIdEncrypt.encrypt("super"));
    	System.out.println(UserIdEncrypt.decrypt(UserIdEncrypt.encrypt("FC97568DA20B4B80BDA3C5B40BB7D1A2")));
    	System.out.println(UserIdEncrypt.getTime(UserIdEncrypt.encrypt("FC97568DA20B4B80BDA3C5B40BB7D1A2")));
    }
	public static String encrypt(String s) {
		byte[] ary = s.getBytes();
		StringBuffer buff = new StringBuffer(Long.toHexString(System.currentTimeMillis()));
		for(int i=0;i<ary.length;i++){
			short num = (short) (256*((int)(Math.random()*120))+ary[i]);
			String str = Integer.toHexString(num);
			buff.append("0000".substring(str.length())).append(str).append("");
		}
		return buff.toString();
	}
	public static String decrypt(String s) {
		String time = Long.toHexString(System.currentTimeMillis());
		s = s.substring(time.length());
		byte[] ary = new byte[s.length()/4];
		for(int i=0;i<s.length();i+=4){
			int tmp = Integer.parseInt(s.substring(i,i+4),16);
			ary[i/4] = (byte) (tmp%256);
		}
		return new String(ary);
	}
	public static Date getTime(String s) {
		String time = Long.toHexString(System.currentTimeMillis());
		s = s.substring(0,time.length());
		return new Date(Long.parseLong(s,16));
	}
}